<?php

include_once 'getAccessToken.php';
include_once 'baseInformatica.php';

if (isset($_GET['mm'])) {
    if ($_GET['mm'] != INTERIOR_SECRET) {
        exit();
    }
} else {
    exit();
}

$json = '{
    "button": [
        {
            "name": "语言介绍", 
            "sub_button": [
                {
                "type":"view",
            	"name":"C语言",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000013&idx=1&sn=aa35f8f47607a3b33a108968f1d1f788&chksm=7aa965b94ddeecaf35401c3c41b4f6c8eec7e70b54ffa9ab8ee179a4a8e4a967b6b9359f5d03&mpshare=1&scene=23&srcid=1106fOAWX3kmAr5D6KoHjXko#rd
"
                }, 
                {
                "type":"view",
            	"name":"Java",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000036&idx=1&sn=c35cac528c652ec59b0c65aa72467414&chksm=7aa965904ddeec8630e784dfde4029998e6af94986bec52f268985274ccace95a843212e6a53&mpshare=1&scene=23&srcid=1106Dlx4PCrey6hTBuPTvWcz#rd
"
                }, 
                {
                "type":"view",
            	"name":"Python",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000039&idx=1&sn=e274e5995dd18ff4ff31cc0f2bab7c6e&chksm=7aa965934ddeec854c0089d07945c1037338c9d9075d61ba741b365902b6feccbc35eda3bdc0&mpshare=1&scene=23&srcid=1106HdpMnQ6bzeH57x7887He#rd
"
                }
            ]
        }, 
        {
            "name": "编程杂谈", 
            "sub_button": [
                {
                "type":"view",
            	"name":"趣味故事",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000017&idx=1&sn=24fde99cbf5f1ef4eada737bc351272f&chksm=7aa965a54ddeecb3fc282b1500facbfcf5172a9c376461ab2d5d041b2abcfc3d876ee4d8edab&mpshare=1&scene=23&srcid=1106fgPCCgXoQ4kjfzNvaE00#rd
"
                }, 
                {
                "type":"view",
            	"name":"算法科普",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000040&idx=1&sn=4e8b971f3131686de6854a79c1bd1ece&chksm=7aa9659c4ddeec8a0938375adbf6b97868c232d0628170afb6f6ffa89b23f5b6cb548b6bfc9a&mpshare=1&scene=23&srcid=11064mbkez3ZAtC0O0MKS6du#rd
"
                },
				 "type":"view",
            	"name":"蓝桥杯",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000059&idx=1&sn=3d141f808446db8e904923a85b647b7d&chksm=7aa9658f4ddeec995f23027e043bb5342cee3fabbc80fbc9cf986012d5b38d57c671100b715a&mpshare=1&scene=23&srcid=1106ok2ehgG5Xn1p0oqQpP6T#rd
"
                }, 
                {
                "type":"view",
            	"name":"ACM",
            	"url":"http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000054&idx=1&sn=79efaba878802b0c900e3564d9490256&chksm=7aa965824ddeec9422b0aa2d3390f2f65a0ec57a80ef6071b75fd0738c1881b999deee8128ec&mpshare=1&scene=23&srcid=1106GuoCz7iBnbVynLzWw0DU#rd"
                }
            ]
        },
        {
            "name": "资源共享", 
            "sub_button":[
            {
                "type":"view",
            	"name":"CSDN社区",
            	"url":"https://www.csdn.net/”
                }, 
                {
                "type":"view",
            	"name":"程序员的梦工厂",
            	"url":"http://www.imooc.com/"
                }, 
				{
                "type":"view",
            	"name":"代码大比拼",
            	"url":"http://www.codevs.cn/info/"
                }
            ]
        }
    ]
}';

$token = GetAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$token";
var_dump(create($json, $url));

function create($data, $url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $out = curl_exec($ch);
    curl_close($ch);
    return $out;
}
